package com.chengqj;

import com.chengqj.dao.UserDO;
import com.chengqj.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Copyright © 2020年 com.qxkj. All rights reserved.
 *
 * @author chengqj
 * 异步插入一条记录  在同一个service中异步就失效了，测试不出效果
 * version 1.0.0 (接口必须带上)
 * @date 2020/11/5 16:43
 */
@Service
public class AsyncUserService {
    @Autowired
    private UserRepository userRepository;

    /**
     * 异步添加一条记录
     *
     * @param userDO
     * @return
     */
    @Async
    @Transactional
    public void insert(UserDO userDO) {
        userRepository.save(userDO);
        throw new RuntimeException();
    }

}
